package com.ruoyi.project.bus.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.bus.domain.BusStudent;
import com.ruoyi.project.bus.service.IBusStudentService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 学生Controller
 * 
 * @author ruoyi
 * @date 2020-05-15
 */
@RestController
@RequestMapping("/bus/student")
public class BusStudentController extends BaseController
{
    @Autowired
    private IBusStudentService busStudentService;

    /**
     * 查询学生列表
     */
    @PreAuthorize("@ss.hasPermi('bus:student:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusStudent busStudent)
    {
        startPage();
        List<BusStudent> list = busStudentService.selectBusStudentList(busStudent);
        return getDataTable(list);
    }

    /**
     * 导出学生列表
     */
    @PreAuthorize("@ss.hasPermi('bus:student:export')")
    @Log(title = "学生", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusStudent busStudent)
    {
        List<BusStudent> list = busStudentService.selectBusStudentList(busStudent);
        ExcelUtil<BusStudent> util = new ExcelUtil<BusStudent>(BusStudent.class);
        return util.exportExcel(list, "student");
    }

    /**
     * 获取学生详细信息
     */
    @PreAuthorize("@ss.hasPermi('bus:student:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(busStudentService.selectBusStudentById(id));
    }

    /**
     * 新增学生
     */
    @PreAuthorize("@ss.hasPermi('bus:student:add')")
    @Log(title = "学生", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusStudent busStudent)
    {
        return toAjax(busStudentService.insertBusStudent(busStudent));
    }

    /**
     * 修改学生
     */
    @PreAuthorize("@ss.hasPermi('bus:student:edit')")
    @Log(title = "学生", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusStudent busStudent)
    {
        return toAjax(busStudentService.updateBusStudent(busStudent));
    }

    /**
     * 删除学生
     */
    @PreAuthorize("@ss.hasPermi('bus:student:remove')")
    @Log(title = "学生", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(busStudentService.deleteBusStudentByIds(ids));
    }
}
